/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020-05-19 15:15
 */
package com.yao.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yao.common.helper.RequestHelper;
import com.yao.common.helper.ValidateHelper;
import com.yao.common.resp.ApiResponse;
import com.yao.sys.entity.dto.UserLoginDto;
import com.yao.sys.service.UserService;

import cn.hutool.core.lang.Console;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户登陆逻辑
 *
 * @author yaoyuming
 * @date 2020/05/19 15:15
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserLoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登陆", notes = "用户登陆")
    public ApiResponse<Object> login(@RequestBody UserLoginDto dto) {
        Console.log("用户登陆信息:{}", dto);

        ValidateHelper.validateNull(dto, new String[] {"userName", "password"});

        String token = userService.login(dto);

        RequestHelper.getResponse().addHeader("access_token", token);

        return ApiResponse.success();
    }
}